<?php
            
use app\model\Theme; 
use app\model\Worker; 


/**
 * Author: cbw
 * Desc: 代言模式
 * Time: 2022/1/6 4:56 下午
 * Email: 17854288794@163.com
 */
class Index_Page extends PluginWebPage {

    /**
     * Desc:代言列表
     * User:cbw
     * Email:17854288794@163.com
     * Time: 2022/1/19 7:27 下午
     * @param $method
     */
    function main($method)
    {
        $method = 'index_main';
        global $_G,$_P,$_S,$_C;
        $system = $_S;
        $config = $_C;
        $themeid = intval($_P['themeid']);
        if($themeid <= 0){
            $themeid = Theme::getDefaultThemenew();
        }
        $themelist = Theme::getAllTheme();
        $page_index = max(1,intval($_P['page']));
        $page_size = 50;
        $page_start = ($page_index-1)*$page_size;

        if (empty($_P['createtime']['start'])){
            $starttime =db_fetchcolumn ( 'SELECT min(addtime) FROM ' . tablename ( t_fans ) );
            $start_day =  date('Y-m-d H:i:s',$starttime);
        }else{
            $start_day =  $_P['createtime']['start'];
            $starttime = strtotime($start_day);
        }
        $end_day = empty($_P['createtime']['end']) ? date('Y-m-d H:i:s',TIMESTAMP): $_P['createtime']['end'] ;
        $endtime = empty($_P['createtime']['end']) ? TIMESTAMP: strtotime($_P['createtime']['end']);

        $status = isset($_P['status'])?$_P['status']:'';
        $status_list = DaiYanModel::getDaiYanStatusArr($themeid);

        $sort = isset($_P['sort'])?$_P['sort']:'daiyan_liked';

        $lists = DaiYanModel::getDaiYanList($themeid,$status,$sort,0,0);
        $list = DaiYanModel::getDaiYanList($themeid,$status,$sort,$page_start,$page_size);
        foreach ($list as $key => $val){
            $r = Worker::getWokerName($_S,$themeid,$val['daiyan_worker_id']);
            $list[$key]['admin_name']=$r['workername'];
            $list[$key]['return_total'] = DaiYanModel::getDaiYanRefundTotal($themeid,$val['uid']);
            $list[$key]['liked_total'] = DaiYanModel::getFriendHelpFlagTotal($themeid,$val['uid']);
        }

        $total = $page_total = count($lists);
        $pager = pagination($page_total,$page_index,$page_size);
        $return_clicent = get_defined_vars();
return $this->view('/daiyan/main/main', $return_clicent);
    }

    /**
     * Desc:代言搜索
     * User:cbw
     * Email:17854288794@163.com
     * Time: 2022/1/19 7:27 下午
     */
    function search()
    {
        $method = 'index_main';
        global $_G,$_P,$_S,$_C;
        $system = $_S;
        $config = $_C;
        $themeid = intval($_P['themeid']);
        if($themeid <= 0){
            $themeid = Theme::getDefaultThemenew();
        }
        $themelist = Theme::getAllTheme();
        $page_index = max(1,intval($_P['page']));
        $page_size = 50;
        $page_start = ($page_index-1)*$page_size;
        if (empty($_P['createtime']['start'])){
            $starttime =db_fetchcolumn ( 'SELECT min(addtime) FROM ' . tablename ( t_fans ) );
            $start_day =  date('Y-m-d H:i:s',$starttime);
        }else{
            $start_day =  $_P['createtime']['start'];
            $starttime = strtotime($start_day);
        }
        $end_day = empty($_P['createtime']['end']) ? date('Y-m-d H:i:s',TIMESTAMP): $_P['createtime']['end'] ;
        $endtime = empty($_P['createtime']['end']) ? TIMESTAMP: strtotime($_P['createtime']['end']);
        $search_data = isset($_P['search_data'])?$_P['search_data']:'';
        if ($search_data){
            $search_data = '%'.$search_data.'%';
        }
        $status = isset($_P['status'])?$_P['status']:'';
        $status_list = DaiYanModel::getDaiYanStatusArr($themeid);

        $sort = isset($_P['sort'])?$_P['sort']:'daiyan_liked';
        $lists = DaiYanModel::searchDaiYanList($themeid,$search_data,0,0,$starttime,$endtime);
        $list = DaiYanModel::searchDaiYanList($themeid,$search_data,$page_start,$page_size,$starttime,$endtime);
        foreach ($list as $key => $val){
            $r = Worker::getWokerName($_S,$themeid,$val['daiyan_worker_id']);
            $list[$key]['admin_name']=$r['workername'];
            $list[$key]['return_total'] = DaiYanModel::getDaiYanRefundTotal($themeid,$val['uid']);
            $list[$key]['liked_total'] = DaiYanModel::getFriendHelpFlagTotal($themeid,$val['uid']);
        }

        $total = $page_total = count($lists);
        $pager = pagination($page_total,$page_index,$page_size);
        $return_clicent = get_defined_vars();
return $this->view('/daiyan/main/main', $return_clicent);
    }

    /**
     * Desc:获取代言下点赞列表
     * User:cbw
     * Email:17854288794@163.com
     * Time: 2022/1/19 7:43 下午
     */
    function liked()
    {
        $method = 'liked_main';
        global $_G,$_P,$_S,$_C;
        $system = $_S;
        $config = $_C;
        $themeid = intval($_P['themeid']);
        if($themeid <= 0){
            $themeid = Theme::getDefaultThemenew();
        }
        $themelist = Theme::getAllTheme();
        $page_index = max(1,intval($_P['page']));
        $page_size = 50;
        $page_start = ($page_index-1)*$page_size;
        $uid = $_P['uid'];

        if (empty($_P['createtime']['start'])){
            $starttime =db_fetchcolumn ( 'SELECT min(addtime) FROM ' . tablename ( t_fans ) );
            $start_day =  date('Y-m-d H:i:s',$starttime);
        }else{
            $start_day =  $_P['createtime']['start'];
            $starttime = strtotime($start_day);
        }
        $end_day = empty($_P['createtime']['end']) ? date('Y-m-d H:i:s',TIMESTAMP): $_P['createtime']['end'] ;
        $endtime = empty($_P['createtime']['end']) ? TIMESTAMP: strtotime($_P['createtime']['end']);


        $lists = DaiYanModel::getFriendHelpFlagByWhere($themeid,$uid,0,0);
        $list = DaiYanModel::getFriendHelpFlagByWhere($themeid,$uid,$page_start,$page_size);

        $total = $page_total = count($lists);
        $pager = pagination($page_total,$page_index,$page_size);
        $return_clicent = get_defined_vars();
return $this->view('/daiyan/main/liked', $return_clicent);
    }

    /**
     * Desc:点赞的搜索
     * User:cbw
     * Email:17854288794@163.com
     * Time: 2022/1/19 7:57 下午
     */
    function searchLiked()
    {
        $method = 'liked_main';
        global $_G,$_P,$_S,$_C;
        $system = $_S;
        $config = $_C;
        $themeid = intval($_P['themeid']);
        if($themeid <= 0){
            $themeid = Theme::getDefaultThemenew();
        }
        $themelist = Theme::getAllTheme();
        $page_index = max(1,intval($_P['page']));
        $page_size = 50;
        $page_start = ($page_index-1)*$page_size;
        $uid = $_P['uid'];

        if (empty($_P['createtime']['start'])){
            $starttime =db_fetchcolumn ( 'SELECT min(addtime) FROM ' . tablename ( t_fans ) );
            $start_day =  date('Y-m-d H:i:s',$starttime);
        }else{
            $start_day =  $_P['createtime']['start'];
            $starttime = strtotime($start_day);
        }
        $end_day = empty($_P['createtime']['end']) ? date('Y-m-d H:i:s',TIMESTAMP): $_P['createtime']['end'] ;
        $endtime = empty($_P['createtime']['end']) ? TIMESTAMP: strtotime($_P['createtime']['end']);
        $search_data = isset($_P['search_data'])?$_P['search_data']:'';

        $lists = DaiYanModel::getFriendHelpFlagByWhere($themeid,$uid,0,0,$start_day,$end_day,$search_data);
        $list = DaiYanModel::getFriendHelpFlagByWhere($themeid,$uid,$page_start,$page_size,$start_day,$end_day,$search_data);

        $total = $page_total = count($lists);
        $pager = pagination($page_total,$page_index,$page_size);
        $return_clicent = get_defined_vars();
return $this->view('/daiyan/main/liked', $return_clicent);
    }

    /**
     * Desc:代言评论列表
     * User:cbw
     * Email:17854288794@163.com
     * Time: 2022/1/19 7:27 下午
     */
    function item()
    {
        $method = 'index_item';
        global $_G,$_P,$_S,$_C;
        $system = $_S;
        $config = $_C;
        $themeid = intval($_P['themeid']);
        if($themeid <= 0){
            $themeid = Theme::getDefaultThemenew();
        }
        $themelist = Theme::getAllTheme();
        $page_index = max(1,intval($_P['page']));
        $page_size = 50;
        $page_start = ($page_index-1)*$page_size;
        $uid = $_P['uid'];

        if (empty($_P['createtime']['start'])){
            $starttime =db_fetchcolumn ( 'SELECT min(addtime) FROM ' . tablename ( t_fans ) );
            $start_day =  date('Y-m-d H:i:s',$starttime);
        }else{
            $start_day =  $_P['createtime']['start'];
            $starttime = strtotime($start_day);
        }
        $end_day = empty($_P['createtime']['end']) ? date('Y-m-d H:i:s',TIMESTAMP): $_P['createtime']['end'] ;
        $endtime = empty($_P['createtime']['end']) ? TIMESTAMP: strtotime($_P['createtime']['end']);

        $lists = DaiYanModel::getDaiYanReturnListOrSearch($themeid,$uid,'',0,0);
        $list = DaiYanModel::getDaiYanReturnListOrSearch($themeid,$uid,'',$page_start,$page_size);
        foreach ($list as $key => $val){
            $r = Worker::getWokerName($_S,$themeid,$val['worker_id']);
            $list[$key]['admin_name']=$r['workername'];
        }

        $total = $page_total = count($lists);
        $pager = pagination($page_total,$page_index,$page_size);
        $return_clicent = get_defined_vars();
return $this->view('/daiyan/main/item', $return_clicent);
    }

    /**
     * Desc:搜索评论列表
     * User:cbw
     * Email:17854288794@163.com
     * Time: 2022/1/19 8:25 下午
     */
    function itemSearch()
    {
        $method = 'index_item';
        global $_G,$_P,$_S,$_C;
        $system = $_S;
        $config = $_C;
        $themeid = intval($_P['themeid']);
        if($themeid <= 0){
            $themeid = Theme::getDefaultThemenew();
        }
        $themelist = Theme::getAllTheme();
        $page_index = max(1,intval($_P['page']));
        $page_size = 50;
        $page_start = ($page_index-1)*$page_size;
        $uid = $_P['uid'];

        if (empty($_P['createtime']['start'])){
            $starttime =db_fetchcolumn ( 'SELECT min(addtime) FROM ' . tablename ( t_fans ) );
            $start_day =  date('Y-m-d H:i:s',$starttime);
        }else{
            $start_day =  $_P['createtime']['start'];
            $starttime = strtotime($start_day);
        }
        $end_day = empty($_P['createtime']['end']) ? date('Y-m-d H:i:s',TIMESTAMP): $_P['createtime']['end'] ;
        $endtime = empty($_P['createtime']['end']) ? TIMESTAMP: strtotime($_P['createtime']['end']);
        $search_data = isset($_P['search_data'])?$_P['search_data']:'';

        $lists = DaiYanModel::getDaiYanReturnListOrSearch($themeid,$uid,$search_data,0,0,$start_day,$end_day);
        $list = DaiYanModel::getDaiYanReturnListOrSearch($themeid,$uid,$search_data,$page_start,$page_size,$start_day,$end_day);
        foreach ($list as $key => $val){
            $r = Worker::getWokerName($_S,$themeid,$val['worker_id']);
            $list[$key]['admin_name']=$r['workername'];
        }

        $total = $page_total = count($lists);
        $pager = pagination($page_total,$page_index,$page_size);
        $return_clicent = get_defined_vars();
return $this->view('/daiyan/main/item', $return_clicent);
    }
}